<template>
  <el-dialog title="角色分配" :visible="value" @close="closeEvent">
    <el-checkbox-group v-model="chiaValse">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div>
        <el-button type="primary" @click="submit">确定</el-button>
        <el-button @click="closeEvent">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { sysRole } from '@/api/setting'
import { sysUser } from '@/api/user.js'
import { sysuseraSsignRoles } from '@/api/employees'
export default {
  props: {
    value: {
      type: Boolean,
      required: true
    }
  },
  data () {
    return {
      chiaValse: [],
      list: [],
      id: ''
    }
  },
  created () {
    this.getData()
  },
  methods: {
    async getData () {
      const res = await sysRole({
        page: 1,
        pagesize: 9999
      })
      this.list = res.data.data.rows
    },
    closeEvent () {
      this.$emit('input', false)
      this.chiaValse = []
    },
    async getUserInfo (id) {
      this.id = id
      const res = await sysUser(id)
      this.chiaValse = res.data.data.roleIds
      console.log('员工啊', res)
    },
    //  确定点击
    async submit () {
      console.log(this.chiaValse)
      await sysuseraSsignRoles({
        id: this.id,
        roleIds: this.chiaValse
      })
      // 提示
      this.$message.success('分配角色成功')
      // 关闭弹窗
      this.closeEvent()
    }
  }
}
</script>

<style></style>
